package com.sibco.client.interactive;

import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;
import com.sibco.client.common.CommUtil;
import com.sibco.client.common.Tools;
import com.sibco.client.system.User;

/**
 * NoticeDatasetListener
 */
public class NoticeDatasetListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset) throws Exception {
	  SqlDataset ds=(SqlDataset)dataset;      
	  String sql="";
	  DoradoContext context = DoradoContext.getContext();
	  User user=(User)context.getAttribute(context.SESSION,"User");
	  sql="SELECT ntc.NOTICE_ID,ntc.NOTICE_NAME,ntc.COMPANY_ID,ntc.NOTICE_TYPE,ntc.CONTENT,ntc.FILE_NAME,ntc.FILE_REAL_PATH,ntc.STATUS,"
		 +"ntc.SEND_MAN,ntc.SEND_DATE,ntc.INPUT_MAN,ntc.INPUT_DATE,ntc.MODIFY_MAN,ntc.MODIFY_DATE,ntc.IS_VALID,"
		 +"u1.REAL_NAME INPUT_MAN_NAME,u2.REAL_NAME SEND_MAN_NAME "
		 +"FROM CLT_COM_NOTICE ntc,clt_rt_user u1,clt_rt_user u2 "
		 +"where ntc.input_man=u1.user_id and ntc.send_man=u2.user_id(+) "
		 +"and ntc.company_id="+user.getCompanyId()+" and ntc.is_valid=1 ";
	  sql+=CommUtil.setConditionSQL(ds);
	  String INPUT_DATE1=ds.parameters().getDate("INPUT_DATE1")==null?"":Tools.format(ds.parameters().getDate("INPUT_DATE1"),"yyyyMMdd"); 
	  String INPUT_DATE2=ds.parameters().getDate("INPUT_DATE2")==null?"":Tools.format(ds.parameters().getDate("INPUT_DATE2"),"yyyyMMdd"); 
	  if(!"".equals(INPUT_DATE1)){
		  sql+= " and to_char(ntc.input_date,'yyyymmdd')>='"+INPUT_DATE1+"'";
	  }
	  if(!"".equals(INPUT_DATE2)){
		  sql+= " and to_char(ntc.input_date,'yyyymmdd')<='"+INPUT_DATE2+"'";
	  }
	  String SEND_DATE1=ds.parameters().getDate("SEND_DATE1")==null?"":Tools.format(ds.parameters().getDate("SEND_DATE1"),"yyyyMMdd"); 
	  String SEND_DATE2=ds.parameters().getDate("SEND_DATE2")==null?"":Tools.format(ds.parameters().getDate("SEND_DATE2"),"yyyyMMdd"); 
	  if(!"".equals(SEND_DATE1)){
		  sql+= " and to_char(ntc.send_date,'yyyymmdd')>='"+SEND_DATE1+"'";
	  }
	  if(!"".equals(SEND_DATE2)){
		  sql+= " and to_char(ntc.send_date,'yyyymmdd')<='"+SEND_DATE2+"'";
	  }
	  sql+=" order by ntc.input_date desc";
	  ds.setSql(sql);
      return true;
  }

  public void afterLoadData(Dataset dataset) throws Exception {

  }

}
